package com.genius.reservation.driver.controller;

import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSONObject;
import com.genius.reservation.common.ResponseRule;
import com.genius.reservation.common.constant.Constant;
import com.genius.reservation.driver.entity.DriverInformation;
import com.genius.reservation.driver.service.IDriverInformationService;
import com.genius.reservation.evaluate.entity.EvaluateInformation;
import com.genius.reservation.reservation.entity.ReservationInformation;
import com.genius.reservation.reservation.service.IReservationInformationService;
import com.genius.reservation.tools.annotation.webLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.Map;

/**
 * <p>
 * 司机信息表 前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2022-05-26
 */
@Api(tags = "驾驶员控制器", value = "驾驶员控制器")
@RestController
@RequestMapping("/reservation/driver")
public class DriverInformationController {
    @Autowired
    IDriverInformationService driverService;

    @Autowired
    IReservationInformationService reservationService;



    //    @PostMapping("/createDriver")
//    ResponseRule createDriver(DriverInformation driver){
//        return driverService.newDriver(driver);
//    }
    @PostMapping("/bindPlague")
    @ApiOperation("绑定三码")
    ResponseRule bindPlague(@ApiParam("包含driverNumber ，dnaReport，healthyCode，tripCard")
                            @RequestParam Map<String, String> body) {
        return driverService.bindPlague(body);
    }

    @PostMapping("/getStartCar")
    @ApiOperation("获取发车详情")
    ResponseRule getStartCar(@RequestBody JSONObject body)
    {
        String startCarId = body.getString("startCarId");
        return driverService.getStartCar(startCarId);
    }


    @PostMapping("/getStartCarInformation")
    @ApiOperation("获取发车信息")
    ResponseRule getStartCarInformation(@ApiParam("订单信息") @RequestBody JSONObject body) {
        String reservationNumber = body.getString("reservationNumber");
        return driverService.getStartCarInformation(reservationNumber);
    }


    @PostMapping("/driverSubmit")
    @ApiOperation("提交司机信息")
    @webLog()
    ResponseRule driverSubmit(@ApiParam("车牌号和驾驶员编号") @RequestBody JSONObject body) {
        Integer startCarId = body.getInteger("startCarId");
        String wxNumber = body.getString("wxNumber");
        String carCode = body.getString("carCode");
        String driverName = body.getString("driverName");
        String phone = body.getString("driverPhone");
        String setOutPlace = body.getString("setOutPlace");
        String reservationNumber = body.getString("reservationNumber");
        String startCarTime = body.getString("startCarTime");
        String[] carImg = body.getJSONArray("carImgLists").toArray(new String[0]);
        String[] healthyImg = body.getJSONArray("healthyImgLists").toArray(new String[0]);
        return driverService.driverSubmit(startCarId, wxNumber, carCode, driverName, phone, setOutPlace, carImg, healthyImg,startCarTime,reservationNumber);
    }

    @PostMapping("/driverEdit")
    @ApiOperation("修改司机信息")
    @webLog()
    ResponseRule driverEdit(@ApiParam("车牌号和驾驶员编号") @RequestBody JSONObject body) {
        Integer startCarId = body.getInteger("startCarId");
        String wxNumber = body.getString("wxNumber");
        String carCode = body.getString("carCode");
        String driverName = body.getString("driverName");
        String phone = body.getString("driverPhone");
        String setOutPlace = body.getString("setOutPlace");
        String[] carImg = body.getJSONArray("carImgLists").toArray(new String[0]);
        String[] healthyImg = body.getJSONArray("healthyImgLists").toArray(new String[0]);
        return driverService.driverEdit(startCarId, wxNumber, carCode, driverName, phone, setOutPlace, carImg, healthyImg);
    }

    @ApiOperation("按照编号搜索驾驶员")
    @PostMapping("/selectDriver")
    ResponseRule selectDriver(@ApiParam("驾驶员编号") @RequestParam String driverNumber) {
        return driverService.selectDriver(driverNumber);
    }

    @ApiOperation("获取所有驾驶员")
    @PostMapping("/getList")
    ResponseRule list(@RequestParam String driverNumber) {
        return ResponseRule.ok(driverService.getList());
    }


    @ApiOperation("解绑车辆")
    @PostMapping("/unbindCar")
    ResponseRule unbind(@ApiParam("驾驶员编号") @RequestParam String driverNumber) {
        return driverService.unbind(driverNumber);
    }

    @ApiOperation("编辑驾驶员信息")
    @PostMapping("/editDriver")
    ResponseRule editDriver(DriverInformation driver) {
        return driverService.editDriver(driver);
    }


    @ApiOperation("确认出发")
    @PostMapping("/setOut")
    ResponseRule setOut(@RequestBody String reservationNumber, @RequestBody Integer startCarId) {
        return driverService.setOut(reservationNumber, startCarId);
    }

//    @ApiOperation("获取所有信息")
//    @GetMapping("/getAllMessage/{userNumber}")
//    ResponseRule getAllMessage(@PathVariable("userNumber")String userNumber){
//        return driverService.getAllMessage(userNumber);
//    }

    @ApiOperation("修改司机信息")
    @PostMapping("/editDriverInformation")
    ResponseRule editDriverInformation(@RequestBody String wxNumber,
                                       @RequestBody String reservationNumber,
                                       @RequestBody String carCode,
                                       @RequestBody String driverName,
                                       @RequestBody String phone,
                                       @RequestBody String setOutPlace,
                                       @RequestBody String[] carImg,
                                       @RequestBody String[] healthyImg) {
        return driverService.editDriverInformation(wxNumber, reservationNumber, carCode, driverName, phone, setOutPlace, carImg, healthyImg);
    }

    @ApiOperation("确认到达")
    @webLog
    @PostMapping("/arriveSubmit")
    ResponseRule arriveSubmit(@RequestBody JSONObject body) {
        String reservationNumber = body.getString("reservationNumber");
        Integer startCarId = body.getInteger("startCarId");
        return driverService.arriveSubmit(reservationNumber, startCarId);
    }

//    @ApiOperation("获取所有信息")
//    @GetMapping("/getAllMessage/{userNumber}")
//    ResponseRule getAllMessage(@PathVariable("userNumber")String userNumber){
//        return driverService.getAllMessage(userNumber);
//    }


    @ApiOperation("驾驶员评价收货员")
    @PostMapping("/evaluate")
    ResponseRule evaluate(@RequestBody JSONObject body) {
        String receiverNumber = body.getString("receiverNumber");
        Integer startCarId = body.getInteger("startCarId");
        Integer operationScore = body.getInteger("operationScore");
        Integer attitudeScore = body.getInteger("attitudeScore");
        String evaluateRemarks = body.getString("evaluateRemarks");
        return driverService.evaluate(receiverNumber, startCarId,operationScore,attitudeScore,evaluateRemarks);
    }


    @ApiOperation("根据驾驶员编号获取所有订单")
    @PostMapping("/getAllReservation")
    ResponseRule getAllReservation(@RequestParam String driverNumber) {
        return reservationService.findReservationByDriver(driverNumber);
    }


    @ApiOperation("获取指定订单详情")
    @PostMapping("/getReservation")
    ResponseRule getReservation(@RequestParam String reservationNumber) {
        return reservationService.findReservation(reservationNumber);
    }


    @ApiOperation("只获取五条订单")
    @PostMapping("/getAllReservationFive")
    ResponseRule getAllReservationFive(@RequestParam String driverNumber) {
        return reservationService.findReservationByDriverFive(driverNumber);
    }

//    @PostMapping("/getAllReservationFive")
//    ResponseRule getAllReservationFive(@RequestParam String driverNumber){
//        return reservationService.findReservationByDriverFive(driverNumber);
//    }

}
